package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TAuthorization;
import com.ruoyi.system.service.ITAuthorizationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车位授权Controller
 * 
 * @author ruoyi
 * @date 2022-11-29
 */
@RestController
@RequestMapping("/system/authorization")
public class TAuthorizationController extends BaseController
{
    @Autowired
    private ITAuthorizationService tAuthorizationService;

    /**
     * 查询车位授权列表
     */
    @PreAuthorize("@ss.hasPermi('system:authorization:list')")
    @GetMapping("/list")
    public TableDataInfo list(TAuthorization tAuthorization)
    {
        startPage();
        List<TAuthorization> list = tAuthorizationService.selectTAuthorizationList(tAuthorization);
        return getDataTable(list);
    }

    /**
     * 导出车位授权列表
     */
    @PreAuthorize("@ss.hasPermi('system:authorization:export')")
    @Log(title = "车位授权", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TAuthorization tAuthorization)
    {
        List<TAuthorization> list = tAuthorizationService.selectTAuthorizationList(tAuthorization);
        ExcelUtil<TAuthorization> util = new ExcelUtil<TAuthorization>(TAuthorization.class);
        util.exportExcel(response, list, "车位授权数据");
    }

    /**
     * 获取车位授权详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:authorization:query')")
    @GetMapping(value = "/{authid}")
    public AjaxResult getInfo(@PathVariable("authid") Long authid)
    {
        return success(tAuthorizationService.selectTAuthorizationByAuthid(authid));
    }

    /**
     * 新增车位授权
     */
    @PreAuthorize("@ss.hasPermi('system:authorization:add')")
    @Log(title = "车位授权", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TAuthorization tAuthorization)
    {
        return toAjax(tAuthorizationService.insertTAuthorization(tAuthorization));
    }

    /**
     * 修改车位授权
     */
    @PreAuthorize("@ss.hasPermi('system:authorization:edit')")
    @Log(title = "车位授权", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TAuthorization tAuthorization)
    {
        return toAjax(tAuthorizationService.updateTAuthorization(tAuthorization));
    }

    /**
     * 删除车位授权
     */
    @PreAuthorize("@ss.hasPermi('system:authorization:remove')")
    @Log(title = "车位授权", businessType = BusinessType.DELETE)
	@DeleteMapping("/{authids}")
    public AjaxResult remove(@PathVariable Long[] authids)
    {
        return toAjax(tAuthorizationService.deleteTAuthorizationByAuthids(authids));
    }
}
